﻿
-- =============================================
-- Author:		<赵洪涛>
-- Create date: <2012-04-27>
-- Description:	<将任务退回到下发人>
-- =============================================
CREATE PROCEDURE [dbo].[proc_Project_Task_Exit]
(
		@TaskId uniqueidentifier
)
AS
BEGIN
	Declare @DownPerson varchar(30),@ExecPersonName nvarchar(30),@DeptId int,@DeptName nvarchar(100)

	Select @DownPerson=DownPerson,@ExecPersonName=RTrim(IsNull(ExecPersonName,'')) From Project_Task Where TaskId=@TaskId And IsFinish=0
	If @DownPerson Is Null
	Begin
		Select 0 As ReturnValue
		Return
	End

	Select @DeptId=departmentid,
	@DeptName=(Select case when len(bmbh)>4 then replicate('┆┄┄',(len(bmbh)-4)/2)+isnull(dname,'') else '◆'+isnull(dname,'') end From department Where id=e.departmentid)
	From Employee e
	Where UserName=@DownPerson

	If @DeptId Is Null
	Begin
		Select -1 As ReturnValue
		Return
	End

	Update Project_Task Set Title=Title+'「'+@ExecPersonName+'退回」',ExecDepartmentId=@DeptId,
	ExecDepartmentName=@DeptName,ExecPerson='',ExecPersonName='',TypeId=1
	Where TaskId=@TaskId And IsFinish=0
	Select @@ROWCOUNT As ReturnValue
	Return
END

